package com.wyw.cor.web.jsp.tag;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.DynamicAttributes;
import javax.servlet.jsp.tagext.TagSupport;

public class Button extends TagSupport implements DynamicAttributes{
	private String value;
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	private Map<String,String> dynamicAttributes = new HashMap();
	private String name;
	@Override
	public void setDynamicAttribute(String uri, String localName, Object value)
			throws JspException {
		// TODO Auto-generated method stub
		dynamicAttributes.put(localName, value.toString());
	}
	
	@Override
	public int doStartTag()throws JspException{
		try{
			StringBuffer html = new StringBuffer();
			html.append("<input type='text' ")
			          .append(" name='").append(name).append("' ")
			          .append("value='").append(value).append("' ");
			Set<String> keys = dynamicAttributes.keySet();
			for(String key:keys){
				html.append(" "+key+"='").append(dynamicAttributes.get(key)).append("' ");
				
			}
			html.append("/>");
			pageContext.getOut().println(html.toString());
		}catch(IOException e){
			e.printStackTrace();
		}
		return this.SKIP_BODY;
	}

}